#!/bin/bash
echo "输入实体名："
read entityName
######################################################################################## 生成实体类
#touch ./model/src/main/java/com/futao/entity/${entityName}Entity.java
# 编辑实体类
# vim ./model/src/main/java/com/futao/entity/${entityName}Entity.java
typeset -l lowerCase
lowerCase=${entityName}
# lowerCase=`echo $lowerCase | tr '[:lower:]' '[:upper:]'`
echo "package com.futao.entity;

      import io.swagger.annotations.ApiModel;
      import io.swagger.annotations.ApiModelProperty;
      import lombok.*;
      import org.hibernate.annotations.DynamicInsert;
      import org.hibernate.annotations.DynamicUpdate;

      import javax.persistence.*;

      /**
       * @author futao
       * Created on $(date "+%Y-%m-%d-%H:%M:%S").
       */
      @NoArgsConstructor
      @AllArgsConstructor
      @Data
      @ApiModel(/*TODO*/)
      @Entity
      @Table(name = \"futao_${lowerCase}\")
      @DynamicUpdate
      @DynamicInsert
      public class ${entityName}Entity extends IdEntity {

          @ApiModelProperty(value = \"名字\")
          @Column(name = \"name\", length = 50)
          private String name;

          @ApiModelProperty(value = \"年龄\")
          @Column(name = \"age\")
          private Integer age;
      }
 ">> ./model/src/main/java/com/futao/entity/${entityName}Entity.java

######################################################################################## Controller
echo "
    package com.futao.controller;

    import com.futao.entity.${entityName}Entity;
    import com.futao.service.${entityName}Service;
    import com.futao.sys.model.MyException;
    import io.swagger.annotations.ApiImplicitParam;
    import io.swagger.annotations.ApiImplicitParams;
    import io.swagger.annotations.ApiOperation;
    import org.springframework.web.bind.annotation.*;
    import springfox.documentation.annotations.ApiIgnore;

    import javax.annotation.Resource;
    import java.util.*;
    /**
     * @author futao
     * Created on $(date "+%Y-%m-%d-%H:%M:%S").
     */
    @RestController
    @RequestMapping(value = \"/${entityName}\")
    public class ${entityName}Controller {

        @Resource
        private ${entityName}Service ${lowerCase}Service;

        }

" >> ./service/src/main/java/com/futao/controller/${entityName}Controller.java

######################################################################################## IService
echo "
    package face.com.futao.service;

    import com.futao.entity.${entityName}Entity;

    import java.util.List;

    /**
     * @author futao
     * Created on $(date "+%Y-%m-%d-%H:%M:%S").
     */
    public interface I${entityName}Service {

    }
" >> ./service/src/main/java/face/com/futao/service/I${entityName}Service.java

######################################################################################## Service
echo "
    package com.futao.service;

    import com.futao.entity.${entityName}Entity;
    import com.futao.sys.model.MyException;
    import face.com.futao.service.I${entityName}Service;
    import lombok.extern.slf4j.Slf4j;
    import org.hibernate.SessionFactory;
    import org.hibernate.criterion.Restrictions;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import javax.annotation.Resource;
    import java.util.List;

    /**
     * @author futao
     * Created on $(date "+%Y-%m-%d-%H:%M:%S").
     */
    @Transactional
    @Service
    @Slf4j
    public class ${entityName}Service implements I${entityName}Service {

    }

" >> ./service/src/main/java/com/futao/service/${entityName}Service.java

######################################################################################## IDao
echo "
    package face.com.futao.dao;

    /**
     * @author futao
     * Created on $(date "+%Y-%m-%d-%H:%M:%S").
     */
    public interface I${entityName}Dao {

    }

" >> ./service/src/main/java/face/com/futao/dao/I${entityName}Dao.java

######################################################################################## Dao
echo "
    package com.futao.dao;

    import face.com.futao.dao.I${entityName}Dao;
    import org.springframework.stereotype.Repository;

    /**
     * @author futao
     * Created on $(date "+%Y-%m-%d-%H:%M:%S").
     */
    @Repository
    public class ${entityName}Dao implements I${entityName}Dao {

    }
" >> ./service/src/main/java/com/futao/dao/${entityName}Dao.java

echo "
//      ┏┛ ┻━━━━━┛ ┻┓
//      ┃　　　　　　 ┃
//      ┃　　　━　　　┃
//      ┃　┳┛　  ┗┳　┃
//      ┃　　　　　　 ┃
//      ┃　　　┻　　　┃
//      ┃　　　　　　 ┃
//      ┗━┓　　　┏━━━┛
//        ┃　　　┃   神兽保佑
//        ┃　　　┃   代码无BUG！
//        ┃　　　┗━━━━━━━━━┓
//        ┃　　　　　　　    ┣┓
//        ┃　　　　         ┏┛
//        ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛
//          ┃ ┫ ┫   ┃ ┫ ┫
//          ┗━┻━┛   ┗━┻━┛
                            "
echo "构建完成"